﻿using Class_Entity.ObjectTwo;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataAccess.ObjectTwo
{
    public class D_Update
    {
        DataTable tb = new DataTable();
        ConnectionToDataBase ex = new ConnectionToDataBase();
        public bool UpdateCompany(Companies fx)
        {

            SqlParameter[] sqlParameters = new SqlParameter[7];
            sqlParameters[0] = new SqlParameter("@A", SqlDbType.VarChar);
            sqlParameters[0].Value = fx.COMPANY_CODE;
            sqlParameters[1] = new SqlParameter("@B", SqlDbType.VarChar);
            sqlParameters[1].Value = fx.COMPANY_NAME;
            sqlParameters[2] = new SqlParameter("@C", SqlDbType.VarChar);
            sqlParameters[2].Value = fx.COMPANY_EMAIL;
            sqlParameters[3] = new SqlParameter("@D", SqlDbType.VarChar);
            sqlParameters[3].Value = fx.COMPANY_ADDRESS;
            sqlParameters[4] = new SqlParameter("@E", SqlDbType.VarChar);
            sqlParameters[4].Value = fx.COMPANY_PHONE;
            sqlParameters[5] = new SqlParameter("@F", SqlDbType.VarChar);
            sqlParameters[5].Value = fx.DESCRIPTION;
            sqlParameters[6] = new SqlParameter("@V", SqlDbType.Int);
            sqlParameters[6].Value = fx.COMPANY_ID;
            return ex.executeUpdateQuery("UpdateCompany", sqlParameters);
        }
        public bool UpdateCity(Cities fx)
        {
            SqlParameter[] sqlParameters = new SqlParameter[4];
            sqlParameters[0] = new SqlParameter("@A", SqlDbType.VarChar);
            sqlParameters[0].Value = fx.CITY_CODE;
            sqlParameters[1] = new SqlParameter("@B", SqlDbType.VarChar);
            sqlParameters[1].Value = fx.CITY_NAME;
            sqlParameters[2] = new SqlParameter("@C", SqlDbType.VarChar);
            sqlParameters[2].Value = fx.DESCRIPTION;
            sqlParameters[3] = new SqlParameter("@V", SqlDbType.Int);
            sqlParameters[3].Value = fx.CITY_ID;
            return ex.executeUpdateQuery("UpdateCity", sqlParameters);
        }
        public bool UpdateBranch(CC_Branches fx)
        {
            SqlParameter[] sqlParameters = new SqlParameter[8];
            sqlParameters[0] = new SqlParameter("@A", SqlDbType.Int);
            sqlParameters[0].Value = fx.COMPANY_ID;
            sqlParameters[1] = new SqlParameter("@B", SqlDbType.Int);
            sqlParameters[1].Value = fx.CITY_ID;
            sqlParameters[2] = new SqlParameter("@C", SqlDbType.VarChar);
            sqlParameters[2].Value = fx.BRANCH_CODE;
            sqlParameters[3] = new SqlParameter("@D", SqlDbType.VarChar);
            sqlParameters[3].Value = fx.BRANCH_NAME;
            sqlParameters[4] = new SqlParameter("@E", SqlDbType.VarChar);
            sqlParameters[4].Value = fx.BRANCH_PHONE;
            sqlParameters[5] = new SqlParameter("@F", SqlDbType.VarChar);
            sqlParameters[5].Value = fx.ADDRESS;
            sqlParameters[6] = new SqlParameter("@G", SqlDbType.VarChar);
            sqlParameters[6].Value = fx.DESCRIPTION;
            sqlParameters[7] = new SqlParameter("@Z", SqlDbType.Int);
            sqlParameters[7].Value = fx.BRANCH_ID;
            return ex.executeUpdateQuery("UpdateBranch", sqlParameters);
        }
        public bool UpdateDistance(Distances fx)
        {
            SqlParameter[] sqlParameters = new SqlParameter[4];
            sqlParameters[0] = new SqlParameter("@A", SqlDbType.Int);
            sqlParameters[0].Value = fx.BRANCH_ID_FROM;
            sqlParameters[1] = new SqlParameter("@B", SqlDbType.Int);
            sqlParameters[1].Value = fx.BRANCH_ID_TO;
            sqlParameters[2] = new SqlParameter("@C", SqlDbType.Float);
            sqlParameters[2].Value = fx.KM;
            sqlParameters[3] = new SqlParameter("@Z", SqlDbType.Int);
            sqlParameters[3].Value = fx.DISTANCE_ID;
            return ex.executeUpdateQuery("UpdateDistance", sqlParameters);
        }
        public bool UpdateService(C_Services fx)
        {
            SqlParameter[] sqlParameters = new SqlParameter[4];
            sqlParameters[0] = new SqlParameter("@A", SqlDbType.VarChar);
            sqlParameters[0].Value = fx.SERVICE_CODE;
            sqlParameters[1] = new SqlParameter("@B", SqlDbType.VarChar);
            sqlParameters[1].Value = fx.SERVICE_NAME;
            sqlParameters[2] = new SqlParameter("@C", SqlDbType.VarChar);
            sqlParameters[2].Value = fx.DESCRIPTION;
            sqlParameters[3] = new SqlParameter("@Z", SqlDbType.Int);
            sqlParameters[3].Value = fx.SERVICE_ID;
            return ex.executeUpdateQuery("UpdateService", sqlParameters);
        }
        public bool UpdateFeePolicy(Delivery_free_polices fx)
        {
            SqlParameter[] sqlParameters = new SqlParameter[8];
            sqlParameters[0] = new SqlParameter("@A", SqlDbType.Int);
            sqlParameters[0].Value = fx.SERVICE_ID;
            sqlParameters[1] = new SqlParameter("@B", SqlDbType.Float);
            sqlParameters[1].Value = fx.DISTANCE_FROM;
            sqlParameters[2] = new SqlParameter("@C", SqlDbType.Float);
            sqlParameters[2].Value = fx.DISTANCE_TO;
            sqlParameters[3] = new SqlParameter("@D", SqlDbType.Float);
            sqlParameters[3].Value = fx.FEE_PER_KM;
            sqlParameters[4] = new SqlParameter("@E", SqlDbType.Float);
            sqlParameters[4].Value = fx.WEIGHT_FROM;
            sqlParameters[5] = new SqlParameter("@F", SqlDbType.Float);
            sqlParameters[5].Value = fx.WEIGHT_TO;
            sqlParameters[6] = new SqlParameter("@G", SqlDbType.Float);
            sqlParameters[6].Value = fx.FEE_PER_KG;
            sqlParameters[7] = new SqlParameter("@Z", SqlDbType.Int);
            sqlParameters[7].Value = fx.FEE_POLICY_ID;
            return ex.executeUpdateQuery("UpdateFeePolicy", sqlParameters);
        }
        public bool UpdateNews(C_News fx)
        {
            SqlParameter[] sqlParameters = new SqlParameter[6];
            sqlParameters[0] = new SqlParameter("@A", SqlDbType.VarChar);
            sqlParameters[0].Value = fx.TITLE;
            sqlParameters[1] = new SqlParameter("@B", SqlDbType.VarChar);
            sqlParameters[1].Value = fx.SUBJECT;
            sqlParameters[2] = new SqlParameter("@C", SqlDbType.NText);
            sqlParameters[2].Value = fx.BODY;
            sqlParameters[3] = new SqlParameter("@D", SqlDbType.DateTime);
            sqlParameters[3].Value = fx.CREATE_DATE;
            sqlParameters[4] = new SqlParameter("@E", SqlDbType.Bit);
            sqlParameters[4].Value = fx.STATUS;
            sqlParameters[5] = new SqlParameter("@z", SqlDbType.Int);
            sqlParameters[5].Value = fx.NEW_ID;
            return ex.executeUpdateQuery("UpdateNews", sqlParameters);
        }
        public bool UpdateOrderA(Orders fx)
        {
            SqlParameter[] sqlParameters = new SqlParameter[23];
            sqlParameters[0] = new SqlParameter("@ORDER_NUMBER", SqlDbType.VarChar);
            sqlParameters[0].Value = fx.ORDER_NUMBER;
            sqlParameters[1] = new SqlParameter("@ORDER_DATE", SqlDbType.VarChar);
            sqlParameters[1].Value = fx.ORDER_DATE;
            sqlParameters[2] = new SqlParameter("@SERVICE_ID", SqlDbType.Int);
            sqlParameters[2].Value = fx.SERVICE_ID;
            sqlParameters[3] = new SqlParameter("@ACCOUNT_ID", SqlDbType.Int);
            sqlParameters[3].Value = fx.ACCOUNT_ID;
            sqlParameters[4] = new SqlParameter("@IS_INTERNAL_DELIVERY", SqlDbType.Int);
            sqlParameters[4].Value = fx.IS_INTERNAL_DELIVERY;
            sqlParameters[5] = new SqlParameter("BRANCH_ID_FROM", SqlDbType.Int);
            sqlParameters[5].Value = fx.BRANCH_ID_FROM;
            sqlParameters[6] = new SqlParameter("@BRANCH_ID_TO", SqlDbType.Int);
            sqlParameters[6].Value = fx.BRANCH_ID_TO;
            sqlParameters[7] = new SqlParameter("@STATUS", SqlDbType.VarChar);
            sqlParameters[7].Value = fx.STATUS;
            sqlParameters[8] = new SqlParameter("@SENDER_NAME", SqlDbType.VarChar);
            sqlParameters[8].Value = fx.SENDER_NAME;
            sqlParameters[9] = new SqlParameter("@SENDER_ADDRESS", SqlDbType.VarChar);
            sqlParameters[9].Value = fx.SENDER_ADDRESS;
            sqlParameters[10] = new SqlParameter("@SENDER_CITY", SqlDbType.Int);
            sqlParameters[10].Value = fx.SENDER_CITY;
            sqlParameters[11] = new SqlParameter("@SENDER_PHONE", SqlDbType.VarChar);
            sqlParameters[11].Value = fx.SENDER_PHONE;
            sqlParameters[12] = new SqlParameter("@RECEIVER_NAME", SqlDbType.VarChar);
            sqlParameters[12].Value = fx.RECEIVER_NAME;
            sqlParameters[13] = new SqlParameter("@RECEIVER_ADDRESS", SqlDbType.VarChar);
            sqlParameters[13].Value = fx.RECEIVER_ADDRESS;
            sqlParameters[14] = new SqlParameter("@RECEIVER_CITY", SqlDbType.Int);
            sqlParameters[14].Value = fx.RECEIVER_CITY;
            sqlParameters[15] = new SqlParameter("@RECEIVER_PHONE", SqlDbType.VarChar);
            sqlParameters[15].Value = fx.RECEIVER_PHONE;
            sqlParameters[16] = new SqlParameter("@MAIL_CODE", SqlDbType.VarChar);
            sqlParameters[16].Value = fx.MAIL_CODE;
            sqlParameters[17] = new SqlParameter("@WEIGHT", SqlDbType.Float);
            sqlParameters[17].Value = fx.WEIGHT;
            sqlParameters[18] = new SqlParameter("@DESCRIPTION", SqlDbType.VarChar);
            sqlParameters[18].Value = fx.DESCRIPTION;
            sqlParameters[19] = new SqlParameter("@TOTAL_DELIVERY_FEE", SqlDbType.Float);
            sqlParameters[19].Value = fx.TOTAL_DELIVERY_FEE;
            sqlParameters[20] = new SqlParameter("@TOTAL_PAID", SqlDbType.Float);
            sqlParameters[20].Value = fx.TOTAL_PAID;
            sqlParameters[21] = new SqlParameter("@RECEIVE_DATE", SqlDbType.VarChar);
            sqlParameters[21].Value = fx.RECEIVE_DATE;
            sqlParameters[22] = new SqlParameter("@Z", SqlDbType.Int);
            sqlParameters[22].Value = fx.ORDER_ID;
            

            return ex.executeUpdateQuery("UpdateOrderA", sqlParameters);
        }
        public bool UpdateOrderB(Orders fx)
        {
            SqlParameter[] sqlParameters = new SqlParameter[15];
            sqlParameters[0] = new SqlParameter("@ORDER_NUMBER", SqlDbType.VarChar);
            sqlParameters[0].Value = fx.ORDER_NUMBER;
            sqlParameters[1] = new SqlParameter("@ORDER_DATE", SqlDbType.VarChar);
            sqlParameters[1].Value = fx.ORDER_DATE;
            sqlParameters[2] = new SqlParameter("@SERVICE_ID", SqlDbType.Int);
            sqlParameters[2].Value = fx.SERVICE_ID;
            sqlParameters[3] = new SqlParameter("@ACCOUNT_ID", SqlDbType.Int);
            sqlParameters[3].Value = fx.ACCOUNT_ID;
            sqlParameters[4] = new SqlParameter("@IS_INTERNAL_DELIVERY", SqlDbType.Int);
            sqlParameters[4].Value = fx.IS_INTERNAL_DELIVERY;
            sqlParameters[5] = new SqlParameter("BRANCH_ID_FROM", SqlDbType.Int);
            sqlParameters[5].Value = fx.BRANCH_ID_FROM;
            sqlParameters[6] = new SqlParameter("@BRANCH_ID_TO", SqlDbType.Int);
            sqlParameters[6].Value = fx.BRANCH_ID_TO;
            sqlParameters[7] = new SqlParameter("@STATUS", SqlDbType.VarChar);
            sqlParameters[7].Value = fx.STATUS;
            sqlParameters[8] = new SqlParameter("@MAIL_CODE", SqlDbType.VarChar);
            sqlParameters[8].Value = fx.MAIL_CODE;
            sqlParameters[9] = new SqlParameter("@WEIGHT", SqlDbType.Float);
            sqlParameters[9].Value = fx.WEIGHT;
            sqlParameters[10] = new SqlParameter("@DESCRIPTION", SqlDbType.VarChar);
            sqlParameters[10].Value = fx.DESCRIPTION;
            sqlParameters[11] = new SqlParameter("@TOTAL_DELIVERY_FEE", SqlDbType.Float);
            sqlParameters[11].Value = fx.TOTAL_DELIVERY_FEE;
            sqlParameters[12] = new SqlParameter("@TOTAL_PAID", SqlDbType.Float);
            sqlParameters[12].Value = fx.TOTAL_PAID;
            sqlParameters[13] = new SqlParameter("@RECEIVE_DATE", SqlDbType.VarChar);
            sqlParameters[13].Value = fx.RECEIVE_DATE;
            sqlParameters[14] = new SqlParameter("@Z", SqlDbType.Int);
            sqlParameters[14].Value = fx.ORDER_ID;
            return ex.executeUpdateQuery("UpdateOrderB", sqlParameters);
        }
    }
}
   